part of 'bloc.dart';

sealed class SingleCustomCollectionFolderPageBlocState {}

class DefaultState implements SingleCustomCollectionFolderPageBlocState {
  DefaultState({
    required this.collectionFolder,
    required this.permittedCollectionListItemIds,
    required this.collectionCreationPermitted,
    required this.collectionFolderExplicitlyDeleted,
    required this.lexicalItemMap,
    required this.collectionListItems,
    this.customLexicalItemDeletionDialogShown = false,
    CollectionFolderDeletionDialogStatusInfo? collectionFolderDeletionDialogStatusInfo,
  }) : collectionFolderDeletionDialogStatusInfo = collectionFolderDeletionDialogStatusInfo ??
            _hiddenCollectionFolderDeletionDialogStatusInfo;

  final CustomCollectionFolder collectionFolder;
  final BuiltSet<String> permittedCollectionListItemIds;
  final bool collectionCreationPermitted;
  final bool collectionFolderExplicitlyDeleted;
  final BuiltMap<String, LexicalItem> lexicalItemMap;
  final BuiltList<CollectionListItem> collectionListItems;
  final bool customLexicalItemDeletionDialogShown;
  final CollectionFolderDeletionDialogStatusInfo collectionFolderDeletionDialogStatusInfo;

  static CollectionFolderDeletionDialogStatusInfo
      get _hiddenCollectionFolderDeletionDialogStatusInfo {
    return CollectionFolderDeletionDialogStatusInfo(
      shown: false,
      deletionModes: BuiltList(),
    );
  }

  DefaultState copyWith({
    CustomCollectionFolder Function()? collectionFolder,
    BuiltSet<String> Function()? permittedCollectionListItemIds,
    bool Function()? collectionCreationPermitted,
    bool Function()? collectionFolderExplicitlyDeleted,
    BuiltMap<String, LexicalItem> Function()? lexicalItemMap,
    BuiltList<CollectionListItem> Function()? collectionListItems,
    bool Function()? customLexicalItemDeletionDialogShown,
    CollectionFolderDeletionDialogStatusInfo Function()? collectionFolderDeletionDialogStatusInfo,
  }) {
    return DefaultState(
      collectionFolder: collectionFolder == null ? this.collectionFolder : collectionFolder(),
      permittedCollectionListItemIds: permittedCollectionListItemIds == null
          ? this.permittedCollectionListItemIds
          : permittedCollectionListItemIds(),
      collectionCreationPermitted: collectionCreationPermitted == null
          ? this.collectionCreationPermitted
          : collectionCreationPermitted(),
      collectionFolderExplicitlyDeleted: collectionFolderExplicitlyDeleted == null
          ? this.collectionFolderExplicitlyDeleted
          : collectionFolderExplicitlyDeleted(),
      lexicalItemMap: lexicalItemMap == null ? this.lexicalItemMap : lexicalItemMap(),
      collectionListItems:
          collectionListItems == null ? this.collectionListItems : collectionListItems(),
      customLexicalItemDeletionDialogShown: customLexicalItemDeletionDialogShown?.call() ?? false,
      collectionFolderDeletionDialogStatusInfo: collectionFolderDeletionDialogStatusInfo?.call() ??
          _hiddenCollectionFolderDeletionDialogStatusInfo,
    );
  }
}

class CollectionReordering implements SingleCustomCollectionFolderPageBlocState {
  const CollectionReordering({
    required this.collectionFolder,
    required this.permittedCollectionListItemIds,
    required this.reorderedCollections,
  });

  final CustomCollectionFolder collectionFolder;
  final BuiltSet<String> permittedCollectionListItemIds;
  final BuiltList<CustomCollection> reorderedCollections;

  CollectionReordering copyWith({
    CustomCollectionFolder Function()? collectionFolder,
    BuiltSet<String> Function()? permittedCollectionListItemIds,
    BuiltList<CustomCollection> Function()? reorderedCollections,
  }) {
    return CollectionReordering(
      collectionFolder: collectionFolder == null ? this.collectionFolder : collectionFolder(),
      permittedCollectionListItemIds: permittedCollectionListItemIds == null
          ? this.permittedCollectionListItemIds
          : permittedCollectionListItemIds(),
      reorderedCollections:
          reorderedCollections == null ? this.reorderedCollections : reorderedCollections(),
    );
  }
}

class CollectionCreation implements SingleCustomCollectionFolderPageBlocState {
  const CollectionCreation({
    required this.collectionFolder,
    required this.permittedCollectionListItemIds,
    required this.collectionCreationPermitted,
    this.validationError,
  });

  final CustomCollectionFolder collectionFolder;
  final BuiltSet<String> permittedCollectionListItemIds;
  final bool collectionCreationPermitted;
  final CustomCollectionTitleValidationError? validationError;

  CollectionCreation copyWith({
    CustomCollectionFolder Function()? collectionFolder,
    BuiltSet<String> Function()? permittedCollectionListItemIds,
    bool Function()? collectionCreationPermitted,
    CustomCollectionTitleValidationError? Function()? validationError,
  }) {
    return CollectionCreation(
      collectionFolder: collectionFolder == null ? this.collectionFolder : collectionFolder(),
      permittedCollectionListItemIds: permittedCollectionListItemIds == null
          ? this.permittedCollectionListItemIds
          : permittedCollectionListItemIds(),
      collectionCreationPermitted: collectionCreationPermitted == null
          ? this.collectionCreationPermitted
          : collectionCreationPermitted(),
      validationError: validationError?.call(),
    );
  }
}

class CollectionDeletion implements SingleCustomCollectionFolderPageBlocState {
  CollectionDeletion({
    required this.collectionFolder,
    required this.permittedCollectionListItemIds,
    required this.selectedCollectionIds,
    this.customLexicalItemDeletionDialogShown = false,
    CollectionDeletionDialogStatusInfo? collectionDeletionDialogStatusInfo,
  }) : collectionDeletionDialogStatusInfo =
            collectionDeletionDialogStatusInfo ?? _hiddenCollectionDeletionDialogStatusInfo;

  final CustomCollectionFolder collectionFolder;
  final BuiltSet<String> permittedCollectionListItemIds;
  final BuiltSet<String> selectedCollectionIds;
  final bool customLexicalItemDeletionDialogShown;
  final CollectionDeletionDialogStatusInfo collectionDeletionDialogStatusInfo;

  static CollectionDeletionDialogStatusInfo get _hiddenCollectionDeletionDialogStatusInfo {
    return CollectionDeletionDialogStatusInfo(
      shown: false,
      deletionModes: BuiltList(),
    );
  }

  CollectionDeletion copyWith({
    CustomCollectionFolder Function()? collectionFolder,
    BuiltSet<String> Function()? permittedCollectionListItemIds,
    BuiltSet<String> Function()? selectedCollectionIds,
    bool Function()? customLexicalItemDeletionDialogShown,
    CollectionDeletionDialogStatusInfo Function()? collectionDeletionDialogStatusInfo,
  }) {
    return CollectionDeletion(
        collectionFolder: collectionFolder == null ? this.collectionFolder : collectionFolder(),
        permittedCollectionListItemIds: permittedCollectionListItemIds == null
            ? this.permittedCollectionListItemIds
            : permittedCollectionListItemIds(),
        selectedCollectionIds:
            selectedCollectionIds == null ? this.selectedCollectionIds : selectedCollectionIds(),
        customLexicalItemDeletionDialogShown: customLexicalItemDeletionDialogShown?.call() ?? false,
        collectionDeletionDialogStatusInfo: collectionDeletionDialogStatusInfo?.call() ??
            _hiddenCollectionDeletionDialogStatusInfo);
  }
}

class CollectionFolderRenaming implements SingleCustomCollectionFolderPageBlocState {
  const CollectionFolderRenaming({
    required this.collectionFolder,
    required this.permittedCollectionListItemIds,
    required this.collectionCreationPermitted,
    this.validationError,
  });

  final CustomCollectionFolder collectionFolder;
  final BuiltSet<String> permittedCollectionListItemIds;
  final bool collectionCreationPermitted;
  final CustomCollectionFolderTitleValidationError? validationError;

  CollectionFolderRenaming copyWith({
    CustomCollectionFolder Function()? collectionFolder,
    BuiltSet<String> Function()? permittedCollectionListItemIds,
    bool Function()? collectionCreationPermitted,
    CustomCollectionFolderTitleValidationError? Function()? validationError,
  }) {
    return CollectionFolderRenaming(
      collectionFolder: collectionFolder == null ? this.collectionFolder : collectionFolder(),
      permittedCollectionListItemIds: permittedCollectionListItemIds == null
          ? this.permittedCollectionListItemIds
          : permittedCollectionListItemIds(),
      collectionCreationPermitted: collectionCreationPermitted == null
          ? this.collectionCreationPermitted
          : collectionCreationPermitted(),
      validationError: validationError?.call(),
    );
  }
}
